﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Text;
using XiuxianGame.人物;

namespace XiuxianGame.DBOper
{
    internal class PlayerOper
    {
        public Player getPlayer(int id)
        {
            Player player = new Player();
            player.Dt = getDPlayer(id);
            return player;
        }
        public Dictionary<string, Player> getNPC()
        {
            DataTable tb =  getDNPC();
            Dictionary<string,Player> npcs = new Dictionary<string, Player>();
            for(int i = 0; i < tb.Rows.Count; i++)
            {
                npcs.Add((string)(tb.Rows[i]["name"]), getPlayer((int)(Double)tb.Rows[i]["id"]));
            }
            return npcs;
        }

        public DataTable getDPlayer(int id)
        {
            String sql = "SELECT * FROM  [player$] where id=" + id + ";";
            //String sql = "SELECT * FROM  [player$] ;";
            OleDbDataAdapter OleDaExcel = new OleDbDataAdapter(sql, DBConnection.conn);
            OleDbCommandBuilder cb = new OleDbCommandBuilder(OleDaExcel);
            /*OleDaExcel.InsertCommand = cb.GetInsertCommand();
            OleDaExcel.UpdateCommand = cb.GetUpdateCommand();
            OleDaExcel.DeleteCommand = cb.GetDeleteCommand();*/
            DataTable dt = new DataTable();
            OleDaExcel.Fill(dt);

            return dt;
        }

        public DataTable getDNPC()
        {
            String sql = "SELECT * FROM  [player$] where id <> 1;";
            //String sql = "SELECT * FROM  [player$] ;";
            OleDbDataAdapter OleDaExcel = new OleDbDataAdapter(sql, DBConnection.conn);
            OleDbCommandBuilder cb = new OleDbCommandBuilder(OleDaExcel);
            /*OleDaExcel.InsertCommand = cb.GetInsertCommand();
            OleDaExcel.UpdateCommand = cb.GetUpdateCommand();
            OleDaExcel.DeleteCommand = cb.GetDeleteCommand();*/
            DataTable dt = new DataTable();
            OleDaExcel.Fill(dt);

            return dt;
        }


    }
}
